import java.util.HashMap;
import java.util.LinkedList;

/**
* class Graph
*
* @author Jim
* @version 1.0
*/
public class Graph
{
	
	protected HashMap adjacencyMap;
	/**
	* Initialize this Graph object to be empty.
	*/
	public Graph()
	{
		adjacencyMap = new HashMap();
	}
	/**
	* Determines if this Graph contains no vertices.
	*
	* @return true - if this Graph contains no vertices.
	*/
	public boolean isEmpty()
	{
		return adjacencyMap.isEmpty();
	}
	/**
	* Determines the number of vertices in this Graph.
	*
	* @return the number of vertices.
	*/
	public int size()
	{
		return adjacencyMap.size();
	}/**
	* Returns the number of edges in this Graph object.
	*
	* @return the number of edges.
	*/
	public int getEdgeCount()
	{
		int count = 0;
		for (int i=0;i<adjacencyMap.size();i++){
			if (adjacencyMap.keySet().toArray()[i] != null){
				LinkedList edges = (LinkedList)
				adjacencyMap.get(adjacencyMap.keySet().toArray()[i]);
				count += edges.size();
			}
		}
		return count;
	}
	/**
	* Adds a specified object as a vertex
	*
	* @param vertex - the specified object
	* @return true - if object was added by this call
	*/
	public boolean addVertex (Object vertex)
	{
		if (adjacencyMap.containsKey(vertex))
			return false;
		adjacencyMap.put (vertex, new LinkedList());
		return true;
	}
	/**
	* Adds an edge, and vertices if not already present
	*
	* @param v1 - the beginning vertex object of the edge
	* @param v2 - the ending vertex object of the edge
	* @return true - if the edge was added by this call
	*/
	public boolean addEdge (Object v1, Object v2)
	{
		addVertex (v1); //addVertex (v2);
		LinkedList l = (LinkedList)adjacencyMap.get(v1);
		l.add(v2);
		return true;
	}
}
